<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <parent></parent>
    </div>
    <template id="child">
        <div>
            <button @click="childClick">发送给父组件</button>
            <input type="text" v-model="msg">
        </div>
        </template>
</body>
<script>
    Vue.component("parent",{
        template:"<div><child @childfn='parfn'>使用子组件：</child>"+
            "<br>从子组件获取的数据为:{{msg}}</div>",
        data(){
            return {
                msg:"我是父组件的内容"
            }
        },
        methods:{
            parfn(playMsg){
                this.msg=playMsg
            }
        }
    });
 

        Vue.component("child",{
            template:"#child",
            data(){
                return{
                    msg:"我是子组件"
                }
            },
            methods:{
                childClick(){
                    this.$emit("childfn",this.msg);
                }
            }
        })
    
    var vm = new Vue({
        el:"#app"
    })
</script>
</html>